﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WPFContrib
{
    /// <summary>
    ///  //Aggregate Actions by Presenter Type stored via string Key
    /// </summary>
    public static class ActionAggregator
    {       
        public static void CreateActionStore<T>()
        {
            Application.Current.Properties[typeof(T)] = new Dictionary<string, Action>();
        }

        public static void Put<T>(string key, Action value)
        {
            ((Dictionary<string, Action>)Application.Current.Properties[typeof(T)]).Add(key, value);
        }

        public static Action Get<T>(string key)
        {
            return (Action)((Dictionary<string, Action>)Application.Current.Properties[typeof(T)])[key];
        }

        public static void Fire<T>(string key)
        {
            ((Action)((Dictionary<string, Action>)Application.Current.Properties[typeof(T)])[key])();
        }

        public static bool Exists<T>(string key)
        {
            return ((Dictionary<string, Action>)Application.Current.Properties[typeof(T)]).ContainsKey(key);
        }

        public static void Remove<T>(string key)
        {
            ((Dictionary<string, Action>)Application.Current.Properties[typeof(T)]).Remove(key);
        }

        public static void ClearGlobalStoreByGuid<T>()
        {
            ((Dictionary<string, Action>)Application.Current.Properties[typeof(T)]).Clear();
        }

    }//end of class
}
